package frame.service.standard;

import bean.ErrorCodeMapping;
import frame.service.context.ServiceContext;

import java.util.Formatter;
import java.util.Map;

public class MiayRuntimeException extends RuntimeException{
    private String errorCode = "999999";
    private String errorMsg = "系统繁忙";
    private Map<String,Object> data;
    private ServiceContext serviceContext;

    public MiayRuntimeException(String errorCode){
        this.errorCode = errorCode;
        this.errorMsg = ErrorCodeMapping.getErrorMsg(errorCode);
    }
    public MiayRuntimeException(Throwable cause){
        super(cause);
        this.errorMsg = cause.getMessage();
    }
    public MiayRuntimeException(String errorCode, Object[] args){
        this.errorCode = errorCode;
        Formatter formatter = new Formatter();
        this.errorMsg = formatter.format(ErrorCodeMapping.getErrorMsg(errorCode), args).toString();
    }

    public String getErrorCode() {
        return errorCode;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }

    public Map<String, Object> getData() {
        return data;
    }

    @Override
    public String getMessage() {
        return errorMsg;
    }

    public ServiceContext getServiceContext() {
        return serviceContext;
    }

    public void setServiceContext(ServiceContext serviceContext) {
        this.serviceContext = serviceContext;
    }
}
